<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="out"></div>
<script>
window.onload = function(){
  function getPosition (callback) {

            if ("geolocation" in navigator) {
                var geo_options = {
                  enableHighAccuracy: true,
                  maximumAge: 0,
                  timeout : 6000
                };
                navigator.geolocation.getCurrentPosition(function(pos) {
                    // 获取到当前位置经纬度
                    var lng = pos.coords.longitude;
                    var lat = pos.coords.latitude;
                    callback(lng,lat);
                }, function(err){
                    alert(err.message);
                }, geo_options);
            } else {
                 console.log("Browser didnt support geolocation");
            }

        };
getPosition(function(lng,lat){
                var out=document.getElementById('out');
                    out.outerHTML='当前经度:'+lng+'<br/>当前纬度'+lat;
             });
}

</script>
</body>
</html>